package com.xuhai

import java.util.Date

import com.alibaba.fastjson.JSON
import com.xuhai.entity.{EnterRateResult, ResultObject}
import com.xuhai.util.{DateUtil, HttpClientUtils, IsPointInPolygon}
import org.apache.commons.lang3.time.FastDateFormat
import org.apache.hadoop.conf.Configuration
import org.apache.spark.sql.{SQLContext, SparkSession}

import scala.collection.JavaConversions._
/**
  * Created by chuxw on 2018/3/29.
  */
object EnterRate {

  def main(args: Array[String]): Unit = {

    val spark = SparkSession.builder.appName("enterRate").master("local[4]").getOrCreate()
    import org.apache.phoenix.spark.SparkSqlContextFunctions
    val sparkSqlContext = new SparkSqlContextFunctions(spark.sqlContext)

    //使用spark sql
    val sqlContext = SQLContext.getOrCreate(spark.sparkContext)
    //phoenix连接配置
    val configuration = new Configuration()
    configuration.set("url", "jdbc:phoenix:slave1,slave2,slave3:2181/hbase")

    var df = sparkSqlContext.phoenixTableAsDataFrame("GPS_DATA", Seq("CITY", "BUSID", "BUSNO", "GPSLAT", "GPSLON", "GPSDATETIME"), Some("CITY = '520100' and BUSID in ('025388') and GPSDATETIME > '20180501223000' and GPSDATETIME < '20180501230000'"), Some("slave1,slave2,slave3:2181"), null,configuration)
    df.registerTempTable("gps")
    sqlContext.sql("select city, busId, gpsDateTime, gpsLat, gpsLon from gps").show()


  }
}
